let vm = new Vue({
    el: '.main-content',
    data: function () {
        return {
            id: "",
            name: "区域管理",
            setting: {
                data: {
                    simpleData: {
                        enable: true,
                        idKey: "id",
                        pIdKey: "parentId"
                    },
                },
                callback: {
                    onClick: this.onClick,
                }
            },
            nodes: []
        }
    },
    methods: {
        init: function () {
            //初始化nodes数据
            axios({
                url: "/guguanjia/area/findAll"
            }).then(resp => {
                this.nodes = resp.data;
                this.nodes[this.nodes.length] = {"id": 0, "name": "区域对象"};
                $.fn.zTree.init($("#select-tree"), this.setting, this.nodes);
            }).catch(error => {
                layer.msg(error.message)
            })
        },

        onClick: function (event, treeId, treeNode) {
            this.name=treeNode.name;
            if (treeNode.id !== 0 && treeNode.id != this.id) {
                parent.layer.aid = treeNode.id;
                parent.layer.parentName = treeNode.name;
                let index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index)

            } else {
                layer.msg("请选择正确的的地区")
            }

        },

    },
    created: function () {
        this.id=parent.layer.aid;
        this.init();
    }

});